package cn.tedu.xzs.admin.questionmanagement.dao.persist.repository.impl;

import cn.tedu.xzs.admin.questionmanagement.dao.persist.mapper.QuestionMapper;
import cn.tedu.xzs.admin.questionmanagement.dao.persist.repository.QuestionRepository;
import cn.tedu.xzs.admin.questionmanagement.pojo.entity.Question;
import cn.tedu.xzs.admin.questionmanagement.pojo.vo.QuestionVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class QuestionRepositoryImpl implements QuestionRepository {
    @Autowired
    private QuestionMapper questionMapper;
    @Override
    public int addNew(Question question) {
        return questionMapper.insert(question);
    }

    @Override
    public Long getLatestQuestionId() {
        return questionMapper.getLatestQuestionId();
    }

    @Override
    public Question getTypeById(Long id) {
        return questionMapper.selectById(id);
    }

    @Override
    public PageInfo<QuestionVO> getQuestionVOPage(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<QuestionVO> questionVOList = questionMapper.getQuestionVOList();
        PageInfo<QuestionVO> pageInfo = new PageInfo<>(questionVOList);
        return pageInfo;
    }


}
